﻿using System;
using System.Collections.Generic;
using System.Text;
using ZWaveApi.Net;
using ZWaveApi.Net.Messenger;
using ZWaveApi.Net.CommandClasses;
using System.Threading;

namespace ControlPoint.ControlAPI {
    public class TimerController : DeviceController {



        public TimerController() :base () {
            this._id = "timer";
            this._name = "Timers";
        }
        public override Dictionary<string, string> AvailableDevices {
            get {
                Dictionary<string, string> ad = new Dictionary<string, string>();
                ad.Add("timer:"+this.GetNextAvailableId().ToString(), "New TimerButton");
                return ad;
            }
        }

        public TimerController(SettingsList settings) : this() {


        }

        public int GetNextAvailableId() { 
            int maxId = 0;

            foreach (TimerButton tb in this.Devices) {
                if ((int)tb.Settings.GetSetting("timerId").Value > maxId) {
                    maxId = (int)tb.Settings.GetSetting("timerId").Value;
                }
            }
            return maxId + 1;
        }

        public override bool AllowMultiple { get { return false; } }

        public override SettingsList Settings {
            get {
                SettingsList settings = new SettingsList();
                settings.SetSetting(new Setting("name", base._name));
                settings.SetSetting(new Setting("id", this._id));
                settings.SetSetting(new Setting("type", this.ToString()));
                return settings;

            }
        }




    }
}